package gui.utils;

import java.awt.*;
import javax.swing.*;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class ProgBar extends JPanel{

    public static int START = 1;
    public static int END = 2;
    public static int UPDATE = 3;

    private JProgressBar pBar;
    private CardLayout layout;
    public ProgBar() {
        super();
        this.setBorder(BorderFactory.createEmptyBorder(9,8,9,8));
        this.setOpaque(false);
        layout = new CardLayout();
        this.setLayout(layout);
        pBar = new JProgressBar();
        pBar.setOpaque(false);
        pBar.setStringPainted(false);
        pBar.setIndeterminate(false);
        this.add(pBar, "show");
        this.add(new JPanel(), "hide");
        layout.show(this, "hide");
    }

    public void idPrg(int which){
        if(which==START){layout.show(this, "show");pBar.setIndeterminate(true);}
        else{layout.show(this, "hide");pBar.setIndeterminate(false);}
    }

    public void dPrg(int which, int val){
        if(which==START){layout.show(this, "show");pBar.setMaximum(val);pBar.setValue(0);}
        else if(which==END){layout.show(this, "hide");pBar.setValue(val);}
        else{pBar.setValue(val);}
    }
}